package com.px.service;

import com.px.client.MaiUserFeignClient;
import com.px.dto.ReturnResult;
import com.px.dto.ReturnResultUtils;
import com.px.pojo.ShUser;
import com.px.utils.MD5Utils;
import com.px.vo.UserVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class MaiUserServiceImpl implements MaiUserService {
    @Resource
    private MaiUserFeignClient maiUserFeignClient;
    /**
     * @param userVo
     * @return
     * @throws Exception
     */
    @Override
    public ReturnResult mai(UserVo userVo) throws Exception {
        //创建实体类
        ShUser shUser = new ShUser();
        //获取邮箱
        shUser.setAccount(userVo.getAccount());
        //获取密码并且加密
        String password = MD5Utils.getMd5(userVo.getPassword(),32);
        //添加密码
        shUser.setPassword(password);
        shUser.setCreatedTime(new Date());
        //调用添加
        boolean mai = maiUserFeignClient.mai(shUser);
        if (mai){
            return ReturnResultUtils.returnSuccess();
        }
        return ReturnResultUtils.returnFail(10023,"失败");
    }
}
